﻿using System;
using System.IO;
using System.Xml.Serialization;

namespace Manso.cBot.Common
{
    [XmlRoot("Configuration"), Serializable]
    public class cBotConfiguration
    {
        public string Server;
        public int Port;
        public string Username;
        public string Password;
        public string Character;        

        public static cBotConfiguration Read(string file)
        {
            cBotConfiguration configuration = null;
            FileStream stream = null;
            try
            {
                stream = File.Open(file, FileMode.Open);
                XmlSerializer serializer = new XmlSerializer(typeof(cBotConfiguration));
                configuration = (cBotConfiguration)serializer.Deserialize(stream);
            }
            catch (Exception ex) { Console.WriteLine(ex.ToString()); }
            finally
            {
                if (stream != null)
                    stream.Close();
            }
            return configuration;
        }
    }
}
